package com.hp.tiger.chapter9;

import java.util.LinkedList;

/**
 * @author XavierDong
 **/
public class RequestQueue {

    private final LinkedList<Request> queues = new LinkedList<>();

    public Request getRequest() {
        synchronized (queues) {
            while (queues.isEmpty()) {
                try {
                    queues.wait();
                } catch (InterruptedException e) {
                    return null;
                }
            }
            return queues.removeFirst();
        }
    }

    public void putRequest(Request request) {
        synchronized (queues) {
            queues.addLast(request);
            queues.notifyAll();
        }
    }
}
